<template>
  <div v-if="giveRule" class="vip-card-give">
    <div class="top">
      <div class="app-main-top-box">
        <div class="title">赠送会员</div>
        <el-button v-if="!$store.getters.banBtnList.includes('BTN_MEMBER_GIVING')" type="primary" size="medium" round @click="openGiveVip">赠送会员</el-button>
      </div>
      <!-- Tips-->
      <div class="app-main-tips-box">
        <div class="title">
          <i class="el-icon-warning" /> 赠送说明
        </div>
        <ul>
          <li>1.你可以在此创建一个会员并赠送给顾客。</li>
          <li>2.顾客即可以通过扫描二维码，或者直接使用兑换码进行领取。</li>
          <li>3.顾客长时间未领取的会员或者其他原因需要撤回的你可以停止这个兑换码的兑换。</li>
        </ul>
      </div>
    </div>

    <!-- tab -->
    <div class="tab">
      <el-tabs v-model="tabName" @tab-click="handleTabClick">
        <el-tab-pane label="会员赠送记录" name="record">
          <give-record ref="giveRecord" :tab-name="tabName" @openGiveDetail="openGiveDetail" />
        </el-tab-pane>
        <el-tab-pane v-if="!$store.getters.banBtnList.includes('TAB_MEMBER_GIVEN_CONFIG')" label="赠送配置" name="config">
          <give-config :give-rule.sync="giveRule" :tab-name="tabName" @getGiveRule="getGiveRule" />
        </el-tab-pane>
      </el-tabs>
    </div>

    <!-- 赠送会员弹框 -->
    <dialog-give-vip
      ref="dialogGiveVip"
      :give-rule="giveRule"
      @openGiveDetail="openGiveDetail"
      @refreshGiveRecord="refreshGiveRecord"
    />
    <dialog-give-detail ref="giveDetail" />
  </div>
</template>

<script>
import { mapActions } from 'vuex'
import { getGiveVipCardRule } from '@/api/vip'
import GiveRecord from './components/GiveRecord'
import GiveConfig from './components/GiveConfig'
import DialogGiveVip from './components/DialogGiveVip'
import DialogGiveDetail from './components/DialogGiveDetail'
export default {
  components: {
    GiveRecord,
    GiveConfig,
    DialogGiveVip,
    DialogGiveDetail
  },
  data() {
    return {
      tabName: 'record',
      giveRule: null
    }
  },
  mounted() {
    // 页面初始化
    this.getGiveRule() // 获取赠送规则
    this.getActiveMaIsOnline() // 获取小程序上线信息
  },
  methods: {
    /**
       *  获取数据
       */
    // 获取小程序是否上线
    ...mapActions(['getAuthMa']),
    getActiveMaIsOnline() {
      this.getAuthMa()
    },

    // 获取会员赠送规则
    getGiveRule() {
      getGiveVipCardRule().then(res => {
        res.data.defaultAmount =
            res.data.defaultAmount === ''
              ? []
              : res.data.defaultAmount.split(',')
        // res.data.payChannel =
        //   res.data.payChannel === "" ? [] : res.data.payChannel.split(",");
        this.giveRule = res.data
      })
    },

    /**
       *  按钮组
       */
    // 打开赠送
    openGiveVip() {
      this.$refs.dialogGiveVip.open()
    },

    // 打开赠送详情
    openGiveDetail(code) {
      this.$refs.giveDetail.open(code)
      // this.$refs.giveRecord.openGiveDetail(code);
    },

    // 切换tab栏
    handleTabClick(tab, event) {},

    /**
       *  方法
       */
    // 赠送成功刷新赠送记录
    refreshGiveRecord() {
      this.$refs.giveRecord.initData()
    }
  }
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
  .top {
    padding: 24px 30px;
    border-radius: 5px 5px 0 0;
    background-color: #fff;
  }
</style>
<style rel="stylesheet/scss" lang="scss">
  /* reset element*/
  .vip-card-give {
    .tab {
      .el-tabs__header {
        padding-left: 30px;
        margin-bottom: 10px;
        background-color: #fff;
        border-radius: 0 0 5px 5px;
      }
      .el-tabs__nav-wrap::after {
        background-color: #fff;
      }
      .el-tabs__active-bar {
        height: 4px;
      }
    }
  }
</style>
